<?php

namespace App\Core\Database;

use Illuminate\Support\Facades\Cache;
use Redis;

class StringCacher extends Cacher
{
    public function get(array $keys, $columns)
    {
        $results = [];

        $values = Redis::mget(array_map(function ($key) {
            return $this->getCacheKey($key);
        }, $keys));

        foreach ($values as $index => $value) {
            $results[$keys[$index]] = ! is_null($value) ? $this->pack($value) : null;
        }

        return $results;
    }


    public function put($data)
    {
        foreach($data as $key => $value) {
            RedisLock::lock($key, function($key, $value) {
                Redis::put($key, $value);
            });
        }
    }

}
